package top.jacktgq.lock.liveLock;

import top.jacktgq.utils.LogUtils;
import top.jacktgq.utils.Sleeper;

/**
 * 
 * @Title: LiveLockDemo.java 
 * @Package top.jacktgq.lock.liveLock 
 * @Description: 活锁：活锁出现在两个线程互相改变对方的结束条件，最后谁也无法结束
 * @author CandyWall   
 * @date 2020年11月2日 上午1:33:31 
 * @version V1.0
 */
public class LiveLockDemo {
	private static volatile int count = 10;
	private static final Object lock = new Object();
	public static void main(String[] args) {
		new Thread(() -> {
			while(count > 0) {
				Sleeper.sleep(1);
				count--;
				LogUtils.log("LiveLockDemo", "count=" + count);
			}
		}, "t1").start();
		new Thread(() -> {
			while(count < 20) {
				Sleeper.sleep(1);
				count++;
				LogUtils.log("LiveLockDemo", "count=" + count);
			}
		}, "t2").start();
	}
}
